// Promise.all([a, b, c]).then(() => {})
// 需要全部完成之后.thenc才会执行

function all(promises) {
    const result = {}
    let count = 0
    return new Promise((resolve, reject) => {
        const addData = (index, value) => {
            result[index] = value
            count++
            if (count === promises.length) resolve(result)
        }

        promises.forEach((promise, index) => {
            if(promise instanceof Promise) {
                promise.then (
                    res => {
                        addData(index, res)
                    },
                    err => {
                        reject(err)
                    }
                )
            }
            else {
                addData(index, )
            }
        });
    })
}
